﻿#region
//Copyright (c) 2016-2022 北京网非科技有限公司(wfdot.com)
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SumiaAccountBook.Biz
{
    public class KVProjectStatus:KVObj
    {
        public enum emProjectStatus
        {
            NotStart = -1,

            Progress = 0,

            Success = 1,

            Failed = -2
        }        

        public KVProjectStatus():base()
        {
            _dict.Add((int)emProjectStatus.NotStart, "尚未开始");
            _dict.Add((int)emProjectStatus.Progress, "进行中");
            _dict.Add((int)emProjectStatus.Success, "成功结束");
            _dict.Add((int)emProjectStatus.Failed, "失败结束");
        }       
    }

    public class KVCashFlowType:KVObj
    {
        public enum emCashFlowType
        {
            In = 1,

            Out = -1
        }

        public KVCashFlowType()
            : base()
        {
            _dict.Add((int)emCashFlowType.In, "收入");
            _dict.Add((int)emCashFlowType.Out, "支出"); 
        }
    }

    public class KVCurrentType:KVObj
    {
        public enum emCurrentType
        {
            In = 1,

            Out = -1
        }

        public KVCurrentType()
            : base()
        {
            _dict.Add((int)emCurrentType.In, "应收");
            _dict.Add((int)emCurrentType.Out, "应付"); 
        }
    }

    public class KVConstHelper
    {
        private static KVConstHelper _Instance;

        /// <summary>
        /// 容器
        /// 每个类型存储一个实例
        /// </summary>
        private Dictionary<string, KVObj> _container = new Dictionary<string, KVObj>();

        private KVConstHelper()
        {
            _container.Add(typeof(KVProjectStatus).Name, new KVProjectStatus());
            _container.Add(typeof(KVCashFlowType).Name, new KVCashFlowType());
            _container.Add(typeof(KVCurrentType).Name, new KVCurrentType());
        }

        public static KVConstHelper GetInstance()
        {
            if(null==_Instance)
            {
                _Instance = new KVConstHelper();
            }
            return _Instance;
        }

        public string GetValue<T>(int key) where T : KVObj
        {
            string typeName = typeof(T).Name;
            if(this._container.ContainsKey(typeName))
            {
                return this._container[typeName].GetValue(key);
            }
            throw new NotSupportedException("不支持类型:"+typeName);
        }

        public List<string> GetAllValue<T>() where T : KVObj
        {
            string typeName = typeof(T).Name;
            if (this._container.ContainsKey(typeName))
            {
                return this._container[typeName].GetAllValue();
            }
            throw new NotSupportedException("不支持类型:" + typeName);
        }

        public int GetKey<T>(string value)
        {
            string typeName = typeof(T).Name;
            if (this._container.ContainsKey(typeName))
            {
                return this._container[typeName].GetKey(value);
            }
            throw new NotSupportedException("不支持类型:" + typeName);
        }
    }
}
